# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Example script shows how to use EasyFilter.

USAGE:
  $ python example.py
"""

__author__ = 'jbenjamin@google.com (Jason Debolt)'

import easy_filter
import datetime


class Foo(easy_filter.EasyFilter):
  """Foo class used for displaying EasyFilter usage.

  Attributes:
    name: String name.
    age: Integer age.
    date: Date object date.
  """

  def __init__(self, name, age, date):
    """Initalizes the Foo class.

    Args:
      name: String name.
      age: Integer age.
      date: Date object date.
    """
    easy_filter.EasyFilter.__init__(self)
    self.name = name
    self.age = age
    self.date = date

  def __repr__(self):
    return 'name: %s, age: %s, date: %s' %  (self.name, self.age, self.date)


def main():
  my_list = [
      Foo(name='steve', age=45, date=datetime.date(2011, 4, 4)),
      Foo(name='jen', age=45, date=datetime.date(2010, 3, 3)),
      Foo(name='kate', age=29, date=datetime.date(2010, 3, 3)),
      Foo(name='jack', age=33, date=datetime.date(2009, 1, 1))]

  print 'Example 1:'
  for item in my_list:
    if item.Filter(name__ne='steve', age=(29, 45)).IsValid():
      print item

  print 'Example 2:'
  for item in my_list:
    if item.Filter(date=datetime.date(2010, 3, 3)).Filter(age__lt=30).IsValid():
      print item

  print 'Example 3:'
  for item in my_list:
    if item.Filter('OR', name='steve', date=datetime.date(2010, 3, 3)).IsValid():
      print item


if __name__ == '__main__':
  main();
